<?php


class ModelToolCustomurl extends Model {

	public function saveUrls($urls) {
		   			$this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query LIKE 'custom=%'");
					
					foreach ($urls as $url) {				
						$qe =  $url['query'];
						if(strpos($url['query'],'='))
						{
							$qe = substr($url['query'],strpos($url['query'],'=')+1,strlen($url['query']));
						}
						$qe = 'custom='.$qe;
						
						foreach ( $url['keyword'] as $language_id => $value) {
							$this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = '" . $qe . "', keyword = '" . $this->db->escape($value) . "',language_id = '" . (int)$language_id . "'");
						
						}
						
						
					}
				
				return true;
	}
	
	

	
	public function getUrls() {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE query LIKE 'custom=%'  
		AND language_id = '" . (int)$this->config->get('config_language_id')."' ");

		return $query->rows;
	}
	
	public function getKeyword($language_id,$custom) {
		$query = $this->db->query("SELECT keyword FROM " . DB_PREFIX . "url_alias WHERE query =  '".$custom."'  
		AND language_id = '" . (int)$language_id."' ");
		
		return $query->row;
	}
	
}
?>